﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SysGroupRoleMenu
    {
    	#region public properties
		[Required(ErrorMessage="GroupID Required")]
		public int GroupID { get; set; }
		[Required(ErrorMessage="MenuID Required")]
		public int MenuID { get; set; }
		[Required(ErrorMessage="RoleID Required")]
		public int RoleID { get; set; }
		#endregion

		#region constructor
		public SysGroupRoleMenu(){ }

		public SysGroupRoleMenu(IDataReader rd)
		{
			this.GroupID = (int)rd["GroupID"];
			this.MenuID = (int)rd["MenuID"];
			this.RoleID = (int)rd["RoleID"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSysGroupRoleMenu.Create(GroupID, MenuID, RoleID);
        }

        private bool Update()
        {
            return DBSysGroupRoleMenu.Update(GroupID, MenuID, RoleID);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(GroupID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }

            if(MenuID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }

            if(RoleID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int GroupID, int MenuID, int RoleID)
        {
            return DBSysGroupRoleMenu.Delete(GroupID, MenuID, RoleID);
        }

        public static List<SysGroupRoleMenu> GetAll()
        {
            return ObjectClass.CreateList<SysGroupRoleMenu>(DBSysGroupRoleMenu.GetAll());
        }

        public static SysGroupRoleMenu GetByKey(int GroupID, int MenuID, int RoleID)
        {
            return ObjectClass.CreateInstance<SysGroupRoleMenu>(DBSysGroupRoleMenu.GetByKey(GroupID, MenuID, RoleID));
        }

        public static List<SysGroupRoleMenu> GetByForeignKeys(int GroupID, int MenuID, int RoleID)
        {
            return ObjectClass.CreateList<SysGroupRoleMenu>(DBSysGroupRoleMenu.GetByForeignKeys(GroupID, MenuID, RoleID));
        }

        public static List<SysGroupRoleMenu> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SysGroupRoleMenu>(DBSysGroupRoleMenu.GetByTop(top, where, order));
        }
		#endregion
	}
}
